import {Component, OnInit, ViewContainerRef} from '@angular/core';
import {BakeCupTest} from '../../../../model/BakeCupTest';
import {NzModalService} from 'ng-zorro-antd/modal';
import {BakecuptesteditComponent} from '../bakecuptestedit/bakecuptestedit.component';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";

@Component({
  selector: 'app-bakecuptestlist',
  templateUrl: './bakecuptestlist.component.html',
  styleUrls: ['./bakecuptestlist.component.css']
})
export class BakecuptestlistComponent implements OnInit {
  tl: Array<BakeCupTest>

  constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef,
              private adminService: AdminService,
              private alertService: AlertService) {
    this.tl = new Array<BakeCupTest>();
    this.initData();
  }

  ngOnInit(): void {
  this.initData()
  }

  initData() {
  this.adminService.getCuptests().then((data:any)=>{
    if(data.msg == "ok"){
      this.tl = data.list
    }else{
      this.alertService.showError("获取杯测数据错误")
    }
  })

  }

  record(id:string) {
    const modalwindow = this.modal.create({
      nzTitle: '杯测信息编辑',
      nzContent: BakecuptesteditComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzComponentParams: {
        id:id
      },

      nzOnOk: () => new Promise(resolve => {
        let temp=modalwindow.getContentComponent().b;
        if(!temp.hbd){
          this.alertService.showWarning('烘焙度必填');
          resolve(false)
        }else if(!temp.bcsj){
          this.alertService.showWarning("杯测时间必填")
          resolve(false)
        }else if(!temp.gx){
          this.alertService.showWarning("干香必填")
          resolve(false)
        }else if(!temp.sx){
          this.alertService.showWarning("湿香必填")
          resolve(false)
        }else if(!temp.fw){
          this.alertService.showWarning("风味必填")
          resolve(false)
        }else if(!temp.hg){
          this.alertService.showWarning("回甘必填")
          resolve(false)
        }else if(!temp.sd){
          this.alertService.showWarning("酸度必填")
          resolve(false)
        }else if(!temp.chd){
          this.alertService.showWarning("醇厚度必填")
          resolve(false)
        }else if(!temp.yzx){
          this.alertService.showWarning("一致性必填")
          resolve(false)
        }else if(!temp.phg){
          this.alertService.showWarning("平衡感必填")
          resolve(false)
        }else if(!temp.gjd){
          this.alertService.showWarning("干净度必填")
          resolve(false)
        }else if(!temp.td){
          this.alertService.showWarning("甜度必填")
          resolve(false)
        }else if(!temp.bcdj){
          this.alertService.showWarning("杯测等级必填")
          resolve(false)
        }
        else {
          modalwindow.getContentComponent().save();
          setTimeout(() => {

            resolve(true);
            this.initData()
            //this.getEmpDetailByEmpid(this.empid);
            //this.loadEmpImg();
          }, 2000)
        }
      })
    })

  }

  getCuptestlistByClqk(c:string){
    this.adminService.getCuptestByClqk(c).then((data:any)=>{
      if(data.msg == "ok"){
        this.tl = data.list
      }else{
        this.alertService.showError("根据处理情况获取杯测失败")
      }
    })
  }

}
